<!--
权限报错

[Vue warn]: Error in directive hasPermi inserted hook: "TypeError: Cannot read properties of undefined (reading 'some')"

found in

<Wpplan> at src\views\modules\Project3_ProcessSchedule\mes\plm\wpplan\index.vue
<ElCard> at packages/card/src/main.vue
  <ElTabPane> at packages/tabs/src/tab-pane.vue
    <ElTabs> at packages/tabs/src/tabs.vue
      <MainContent> at src\views\main-content.vue
        <Main> at src\views\main.vue
          <App> at src\App.vue
            <Root>
-->


<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">

<!--  v-hasPermi="['plm:wpplan:add']" 此处会有权限报错       -->
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['plm:wpplan:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['plm:wpplan:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['plm:wpplan:remove']"
        >删除</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['plm:wpplan:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wpplanList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="总段号" align="center" prop="totalNumber" />
      <el-table-column label="分段号" align="center" prop="branchNumber" />
      <el-table-column label="分段类型" align="center" prop="branchNumberType" />
      <el-table-column label="长m" align="center" prop="longM" />
      <el-table-column label="宽m" align="center" prop="widthM" />
      <el-table-column label="高m" align="center" prop="highM" />
      <el-table-column label="分段重量t" align="center" prop="branchT" />
      <el-table-column label="开始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总计划ID" align="center" prop="planId" />
      <el-table-column label="备料开始时间" align="center" prop="mpSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.mpSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备料完成时间" align="center" prop="mpETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.mpETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="切割开始时间" align="center" prop="cuttingSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cuttingSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="切割完成时间" align="center" prop="cuttingETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cuttingETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="加工开始时间" align="center" prop="machiningSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.machiningSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="加工完成时间" align="center" prop="machiningETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.machiningETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="小组开始时间" align="center" prop="xgroupSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.xgroupSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="小组完成时间" align="center" prop="xgroupETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.xgroupETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="中组开始时间" align="center" prop="zgroupSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zgroupSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="中组完成时间" align="center" prop="zgroupETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zgroupETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="大组开始时间" align="center" prop="dgroupSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dgroupSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="大组完成时间" align="center" prop="dgroupETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dgroupETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="火工校正开始时间" align="center" prop="pcSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pcSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="火工校正完成时间" align="center" prop="pcETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pcETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预舾装开始时间" align="center" prop="poSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.poSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预舾装完成时间" align="center" prop="poETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.poETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="一次总组开始时间" align="center" prop="pggSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pggSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="一次总组完成时间" align="center" prop="pggETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pggETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="分段涂装开始时间" align="center" prop="bpSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bpSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="分段涂装完成时间" align="center" prop="bpETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bpETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="二次总组开始时间" align="center" prop="sggSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sggSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="二次总组完成时间" align="center" prop="sggETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sggETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总段舾装开始时间" align="center" prop="gsoSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gsoSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总段舾装完成时间" align="center" prop="gsoETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gsoETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总段涂装开始时间" align="center" prop="gspSTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gspSTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总段涂装完成时间" align="center" prop="gspETime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gspETime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['plm:wpplan:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['plm:wpplan:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改工序计划对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px"  append-to-body>
      <el-form ref="form" :inline="true" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="总段号" prop="totalNumber">
          <el-input v-model="form.totalNumber" placeholder="请输入总段号" />
        </el-form-item>
        <el-form-item label="分段号" prop="branchNumber">
          <el-input v-model="form.branchNumber" placeholder="请输入分段号" />
        </el-form-item>
        <el-form-item label="分段类型" prop="branchNumberType">
          <el-input v-model="form.branchNumberType" placeholder="请输入分段类型" />
        </el-form-item>
        <el-form-item label="长m" prop="longM">
          <el-input v-model="form.longM" placeholder="请输入长m" />
        </el-form-item>
        <el-form-item label="宽m" prop="widthM">
          <el-input v-model="form.widthM" placeholder="请输入宽m" />
        </el-form-item>
        <el-form-item label="高m" prop="highM">
          <el-input v-model="form.highM" placeholder="请输入高m" />
        </el-form-item>
        <el-form-item label="分段重量t" prop="branchT">
          <el-input v-model="form.branchT" placeholder="请输入分段重量t" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker clearable
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker clearable
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总计划ID" prop="planId">
          <el-input v-model="form.planId" placeholder="请输入总计划ID" />
        </el-form-item>
        <el-form-item label="备料开始时间" prop="mpSTime">
          <el-date-picker clearable
            v-model="form.mpSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择备料开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备料完成时间" prop="mpETime">
          <el-date-picker clearable
            v-model="form.mpETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择备料完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="切割开始时间" prop="cuttingSTime">
          <el-date-picker clearable
            v-model="form.cuttingSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择切割开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="切割完成时间" prop="cuttingETime">
          <el-date-picker clearable
            v-model="form.cuttingETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择切割完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="加工开始时间" prop="machiningSTime">
          <el-date-picker clearable
            v-model="form.machiningSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择加工开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="加工完成时间" prop="machiningETime">
          <el-date-picker clearable
            v-model="form.machiningETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择加工完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="小组开始时间" prop="xgroupSTime">
          <el-date-picker clearable
            v-model="form.xgroupSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择小组开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="小组完成时间" prop="xgroupETime">
          <el-date-picker clearable
            v-model="form.xgroupETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择小组完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="中组开始时间" prop="zgroupSTime">
          <el-date-picker clearable
            v-model="form.zgroupSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择中组开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="中组完成时间" prop="zgroupETime">
          <el-date-picker clearable
            v-model="form.zgroupETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择中组完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="大组开始时间" prop="dgroupSTime">
          <el-date-picker clearable
            v-model="form.dgroupSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择大组开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="大组完成时间" prop="dgroupETime">
          <el-date-picker clearable
            v-model="form.dgroupETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择大组完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="火工校正开始时间" prop="pcSTime">
          <el-date-picker clearable
            v-model="form.pcSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择火工校正开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="火工校正完成时间" prop="pcETime">
          <el-date-picker clearable
            v-model="form.pcETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择火工校正完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预舾装开始时间" prop="poSTime">
          <el-date-picker clearable
            v-model="form.poSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预舾装开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预舾装完成时间" prop="poETime">
          <el-date-picker clearable
            v-model="form.poETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预舾装完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="一次总组开始时间" prop="pggSTime">
          <el-date-picker clearable
            v-model="form.pggSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择一次总组开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="一次总组完成时间" prop="pggETime">
          <el-date-picker clearable
            v-model="form.pggETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择一次总组完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分段涂装开始时间" prop="bpSTime">
          <el-date-picker clearable
            v-model="form.bpSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分段涂装开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分段涂装完成时间" prop="bpETime">
          <el-date-picker clearable
            v-model="form.bpETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分段涂装完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="二次总组开始时间" prop="sggSTime">
          <el-date-picker clearable
            v-model="form.sggSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择二次总组开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="二次总组完成时间" prop="sggETime">
          <el-date-picker clearable
            v-model="form.sggETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择二次总组完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总段舾装开始时间" prop="gsoSTime">
          <el-date-picker clearable
            v-model="form.gsoSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择总段舾装开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总段舾装完成时间" prop="gsoETime">
          <el-date-picker clearable
            v-model="form.gsoETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择总段舾装完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总段涂装开始时间" prop="gspSTime">
          <el-date-picker clearable
            v-model="form.gspSTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择总段涂装开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总段涂装完成时间" prop="gspETime">
          <el-date-picker clearable
            v-model="form.gspETime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择总段涂装完成时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addWpplan, delWpplan, getWpplan, listWpplan, updateWpplan} from "@/api/mes/plm/wpplan";

export default {
  name: "Wpplan",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工序计划表格数据
      wpplanList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询工序计划列表 */
    getList() {
      this.loading = true;
listWpplan(this.queryParams).then(response => {
        // console.log(response.data)
        this.wpplanList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,        totalNumber: null,        branchNumber: null,        branchNumberType: null,        longM: null,        widthM: null,        highM: null,        branchT: null,        startTime: null,        endTime: null,        planId: null,        mpSTime: null,        mpETime: null,        cuttingSTime: null,        cuttingETime: null,        machiningSTime: null,        machiningETime: null,        xgroupSTime: null,        xgroupETime: null,        zgroupSTime: null,        zgroupETime: null,        dgroupSTime: null,        dgroupETime: null,        pcSTime: null,        pcETime: null,        poSTime: null,        poETime: null,        pggSTime: null,        pggETime: null,        bpSTime: null,        bpETime: null,        sggSTime: null,        sggETime: null,        gsoSTime: null,        gsoETime: null,        gspSTime: null,        gspETime: null,        createTime: null      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工序计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWpplan(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改工序计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWpplan(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWpplan(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除工序计划编号为"' + ids + '"的数据项？').then(function() {
        return delWpplan(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('plm/wpplan/export', {
        ...this.queryParams
      }, `wpplan_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
